package cn.itcast.search.conreoller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.Item;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    //全量数据导入
    @GetMapping("/importItemData")
    public ResultDTO addES() {
        return searchService.addES();
    }

    //搜索栏自动补全接口
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return searchService.getSuggestions(prefix);
    }

    //过滤项聚合功能
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody SearchReqDTO searchReqDTO) {
        return searchService.getFilters(searchReqDTO);
    }

    //基本搜索功能
    @PostMapping("/list")
    public PageDTO<ItemDoc> findGoods(@RequestBody SearchReqDTO searchReqDTO) {

        return searchService.findGoods(searchReqDTO);
    }
}
